package net.zoneland.knowledge.service;

import net.zoneland.knowledge.model.WorkApplyInfo;
import net.zoneland.knowledge.service.bean.ResultInfo;
import net.zoneland.uniflow.client.ProcessQueryParam;
import net.zoneland.uniflow.client.ReadQueryParam;
import net.zoneland.uniflow.client.TaskQueryParam;
import net.zoneland.uniflow.client.UserInfo;

import java.util.List;
import java.util.Map;

/**
 * @version v1.0
 * @ClassName: UniflowService
 * @Description: 统一流程接口
 * @Author: Pbody
 * @Date: 2020/3/23 17:44
 */
public interface UniFlowService {


    /**
     * 启动流程
     * @Author Pbody
     * @Date 18:00 2020/5/19
     * @Param [businessProcess, applicant, applyId, applyTitle, submit, handlers, extendData]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo startProcess(String businessProcess, UserInfo applicant, String applyId,
                            String applyTitle, boolean submit, UserInfo[] handlers, Map<String, String> extendData);
    /**
     * 查询扩展参数
     * @Author Pbody
     * @Date 18:00 2020/5/19
     * @Param [piid, paramNames]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo queryExtendData(String piid, String[] paramNames);

    /**
     * 设置扩展参数
     * @Author Pbody
     * @Date 18:13 2020/5/19
     * @Param [piid, extendData]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo setExtendData(String piid, Map<String, String> extendData);

    /**
     * 删除流程
     * @Author Pbody
     * @Date 18:14 2020/5/19
     * @Param [piid, applicant, notion]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo deleteProcess(String piid, UserInfo applicant, String notion);

    /**
     * 任务处理
     * @Author Pbody
     * @Date 18:14 2020/5/19
     * @Param [tiid, handler, decision, option, notion, nextNode, nextHandlers, extendData, newApplyTitle]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo completeTask(String tiid, UserInfo handler, String decision,
                            String option, String notion, String nextNode, UserInfo[] nextHandlers,
                            Map<String, String> extendData, String newApplyTitle);

    /**
     * 处理待办。
     * @param tiid 任务实例id
     * @param handler 处理人
     * @param decision 决策选项
     * @param option 决策名称
     * @param notion 处理意见
     * @return 处理结果
     */
    ResultInfo completeTask(String tiid, UserInfo handler, String decision,
                            String option, String notion);

    /**
     * 代办,已办任务查询
     * @Author Pbody
     * @Date 18:14 2020/5/19
     * @Param [param, page, pageSize]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo queryTasksByPage(TaskQueryParam param, int page, int pageSize);

    /**
     * 代办,已办任务查询
     * @Author Pbody
     * @Date 18:14 2020/5/19
     * @Param [param, page, pageSize]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo queryTasksByPageForWorkCenter(TaskQueryParam param, int page, int pageSize);

    /**
     * 获取工单ID和主工单信息Map.
     * @param workApplys 工单列表
     * @return 工单ID与主工单信息Map
     */
    Map<String, WorkApplyInfo> getApplyIdMainApplyMap(List<WorkApplyInfo> workApplys);

    /**
     * 待阅,已阅任务查询
     * @Author Pbody
     * @Date 18:21 2020/5/19
     * @Param [param, page, pageSize]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo queryReadsByPage(ReadQueryParam param, int page, int pageSize);

    /**
     * 查询任务决策
     * @Author Pbody
     * @Date 18:23 2020/5/19
     * @Param [systemId, businessProcess, node]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo queryTaskDecisions(String systemId, String businessProcess, String node);

    /**
     * 获取审批
     * @Author Pbody
     * @Date 18:23 2020/5/19
     * @Param [tiid]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo getApprove(String tiid);

    /**
     * 根据任务实例ID查询任务
     * @Author Pbody
     * @Date 18:25 2020/5/19
     * @Param [tiid]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo getTask(String tiid);

    /**
     * 流程任务转交
     * @Author Pbody
     * @Date 18:35 2020/5/19
     * @Param [tiid, nextHandlers, option, notion]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo transferTask(String tiid, UserInfo[] nextHandlers, String option, String notion);

    /**
     * 查询能否退回
     * @Author Pbody
     * @Date 18:36 2020/5/19
     * @Param [tiid]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo canReject(String tiid);

    /**
     * 查询流程实例
     * @Author Pbody
     * @Date 18:36 2020/5/19
     * @Param [processQueryParam]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo queryProcessInstances(ProcessQueryParam processQueryParam);

    /**
     * 创建阅办
     * @Author Pbody
     * @Date 18:37 2020/5/19
     * @Param [piid, node, owners, readUrl, readTitle, extendData, creator, additionFlag]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo createReads(String piid, String node, UserInfo[] owners, String readUrl,
                           String readTitle, Map<String, String> extendData, UserInfo creator, int additionFlag) ;

    /**
     * 获取阅读项
     * @Author Pbody
     * @Date 18:38 2020/5/19
     * @Param [riid]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo getRead(String riid);

    /**
     * 完成阅办
     * @Author Pbody
     * @Date 18:40 2020/5/19
     * @Param [riid, notion]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo completeRead(String riid, String notion);

    /**
     * 查询任务扩展数据
     * @Author Pbody
     * @Date 18:53 2020/5/19
     * @Param [tiid, extendParamNames]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo queryTaskExtendData(String tiid, String[] extendParamNames);

    /**
     * 设置阅读扩展数据
     * @Author Pbody
     * @Date 18:54 2020/5/19
     * @Param [riid, extendData]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo setReadExtendData(String riid, Map<String, String> extendData);

    /**
     * 查询阅读扩展数据
     * @Author Pbody
     * @Date 18:55 2020/5/19
     * @Param [riid, extendParamNames]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo queryReadExtendData(String riid, String[] extendParamNames);

    /**
     * 查询前任务扩展数据
     * @Author Pbody
     * @Date 18:55 2020/5/19
     * @Param [tiid, extendParamNames]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo queryPreTaskExtendData(String tiid, String[] extendParamNames);

    /**
     * 设置任务扩展数据
     * @Author Pbody
     * @Date 18:56 2020/5/19
     * @Param [tiid, extendData]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo setTaskExtendData(String tiid, Map<String, String> extendData);

    /**
     * 流程退回
     * @Author Pbody
     * @Date 17:55 2020/5/19
     * @Param [tiid, option, notion, extendData]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo reject(String tiid, String option, String notion, Map<String, String> extendData);

    /**
     * 查询流程模板节点
     * @Author Pbody
     * @Date 17:55 2020/5/19
     * @Param [businessProcess, templateVer, nodeId]
     * @return net.zoneland.auditCloud.biz.result.ResultInfo
     **/
    ResultInfo queryProcessTemplateNode(String businessProcess, int templateVer, String nodeId);

    /**
     * 查询业务流程信息
     * @Param systemId 系统标识
     * @Param businessProcess 业务流程名称
     * @Param bizCategory 业务种类
     * @Param roles 角色
     * @Param keywords 关键字
     * @Param provinceId 省份编号
     * @return ResultInfo
     **/
    ResultInfo queryBusinessProcess(final String systemId, final String templateId, final String businessProcess, final String bizCategory, final String[] roles, final String[] keywords, final String  provinceId);

    /**
     * 发起并跳转流程.
     * @param businessProcess 流程模板编号
     * @param applicant 申请人
     * @param applyId 工单号
     * @param applyTitle 工单名称
     * @param jumpNode 节点id
     * @param nodeHandlers 节点管理员
     * @param extendData 额外阐述
     * @return 任务节点信息
     */
    ResultInfo startAndJumpTask(String businessProcess, UserInfo applicant, String applyId, String applyTitle, String jumpNode, UserInfo[] nodeHandlers, Map<String, String> extendData) throws Exception;

    /**
     * 根据工单号查询待办任务集合.
     * @param business 业务流程
     * @param applyId 工单号
     * @return 任务集合
     */
    ResultInfo queryTasksByApplyId(String business, String applyId);

    /**
     * 分页查询流程实例.
     * @param param 查询参数
     * @param page 当前页
     * @param pageSize 每页记录数
     * @return 流程实例结果
     */
    ResultInfo queryProcessInstancesByPage(ProcessQueryParam param, Integer page, Integer pageSize);

    /**
     * 恢复任务.
     * @param tiid 任务id
     * @return 结果
     */
    ResultInfo resumeTask(String tiid);

    /**
     * 挂起任务.
     * @param tiid 任务id
     * @return 结果
     */
    ResultInfo suspendTask(String tiid);

    /**
     * 撤回任务.
     * @param tiid 任务id
     * @param notion 撤回原因
     * @return 结果
     */
    ResultInfo revokeTask(String tiid, String notion);

    /**
     * 复活流程.
     * @param piid 业务流程id
     * @param nodeId 节点编号
     * @param nodeHandlers 节点处理人
     * @param applicant 发起人
     * @param notion 原因
     * @return 结果
     */
    ResultInfo syncReliveProcess(String piid, String nodeId, UserInfo[] nodeHandlers, UserInfo applicant, String notion);

    /**
     * 将工单发送指定环节上去.
     * <p>其逻辑在于，通过业务驱动流程，而忽略流程本身的流转规则（即流程图上的决策）</p>
     * <p>其实现方式为，在途流程通过跳转达到目标环节；已结束流程通过复活达到目标环节</p>
     * @param workApplyInfo 要发送的工单对象
     * @param nodeId 要发送到的节点编号
     * @param nodeHandlers 节点处理人
     * @param applicant 发起人
     * @param notion 原因
     * @return 结果
     */
    ResultInfo sendTheApplyToNode(WorkApplyInfo workApplyInfo, String nodeId, UserInfo[] nodeHandlers, UserInfo applicant, String notion);

    /**
     * 跳转任务.
     * @param tiid 任务实例id
     * @param nodeId 节点编号
     * @param nodeHandlers 节点处理人
     * @param handler 当前处理人（发起跳转的人）
     * @param notion 原因
     * @return 结果
     */
    ResultInfo jump(String tiid, String nodeId, UserInfo[] nodeHandlers, UserInfo handler, String notion);

    /**
     * 流程跳转.
     *
     * @param piid         流程实例id
     * @param nodeId       节点编号
     * @param nodeHandlers 节点处理人
     * @param handler      当前处理人（发起跳转的人）
     * @param decision      决策
     * @param notion       原因
     * @return 结果
     */
    public ResultInfo jumpToNode(String piid, String nodeId, UserInfo[] nodeHandlers, UserInfo handler, String decision, String notion);

    /**
     * 停止流程.
     * @param piid 流程实例id
     * @param applicant 申请人
     * @param notion 申请原因
     * @return
     */
    ResultInfo stopProcess(String piid, final UserInfo applicant,  String notion);

    /**
     *
     * @param param 查阅参数
     * @return 阅读项实例
     */
    ResultInfo queryReads(ReadQueryParam param);

}
